package com.insta.formation.library;

import java.util.Date;

import com.insta.formation.library.dao.IBookDao;
import com.insta.formation.library.dao.IExemplaryDao;
import com.insta.formation.library.dao.IRentDao;
import com.insta.formation.library.dao.IUserDao;
import com.insta.formation.library.dao.impl.BookDaoImpl;
import com.insta.formation.library.dao.impl.ExemplaryDaoImpl;
import com.insta.formation.library.dao.impl.RentDaoImpl;
import com.insta.formation.library.dao.impl.UserDaoImpl;
import com.insta.formation.library.model.IBook;
import com.insta.formation.library.model.IExemplary;
import com.insta.formation.library.model.IRentBook;
import com.insta.formation.library.model.IUser;
import com.insta.formation.library.model.impl.BookImpl;
import com.insta.formation.library.model.impl.ExemplaryImpl;
import com.insta.formation.library.model.impl.Rent;
import com.insta.formation.library.model.impl.UserImpl;

public enum Libraryfactory {

	INSTANCE;

	public IBook createBook(String _isbn, String _author, String _name)
	{
		return new BookImpl(_isbn, _name, _author);
	}

	public IBook createBook(int _id, String _isbn, String _author, String _name)
	{
		return new BookImpl(_id, _isbn, _name, _author);
	}

	public IExemplary createExemplaire(IBook _book)
	{
		return new ExemplaryImpl(_book);
	}

	public IRentBook createRentBook(IUser _user, IBook _book)
	{
		return new Rent(_user, _book);
	}

	// pour le DAO
	public IRentBook createRentBook(int _id, IUser _user, IBook _book, Date _startDate, Date _returnDate, boolean _isReturn)
	{
		return new Rent(_id, _user, _book, _startDate, _returnDate, _isReturn);
	}

	public IUser createUser(String _login, String _password, String _firstName, String _lastName, String _email, boolean isAdmin)
	{
		IUser user = new UserImpl();
		user.setLogin(_login);
		user.setPassword(_password);
		user.setFirstName(_firstName);
		user.setLastName(_lastName);
		user.setEmail(_email);
		user.setAdmin(isAdmin);
		return user;
	}

	/**
	 * Retourne le DAO associé aux utilisateurs
	 * 
	 * @return DAO associé aux utilisateurs
	 */
	public IUserDao createUserDao()
	{
		return new UserDaoImpl();
	}

	/**
	 * Retourne le DAO associé aux livres
	 * 
	 * @return DAO associé aux livres
	 */
	public IBookDao createBookDao()
	{
		return new BookDaoImpl();
	}

	/**
	 * Retourne le DAO associé aux locations
	 * 
	 * @return DAO associé aux locations
	 */
	public IRentDao createRentDao()
	{
		return new RentDaoImpl();
	}

	/**
	 * Retourne le DAO associé aux exemplaires de livres
	 * 
	 * @return DAO associé aux exemplaires de livres
	 */
	public IExemplaryDao createExemplaryDao()
	{
		return new ExemplaryDaoImpl();
	}

	// public IRentManager createRentManager(ILibrary _library)
	// {
	// return new RentManager(_library);
	// }
}
